package com.xbongbong.pro.enums.fund.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 在线支付流水状态枚举
 * @author zcp
 * @version v1.0
 * @since v1.0
 */
@Getter
public enum OnlinePaymentFlowStatusEnum {

    /**
     * 1、完成
     */
    SUCCESS("1", "enum.onlinePaymentFlowStatus.name.success", "enum.onlinePaymentFlowStatus.distributorName.success"),
    /**
     * 2、失败
     */
    FAIL("2", "enum.onlinePaymentFlowStatus.name.fail", "enum.onlinePaymentFlowStatus.distributorName.fail"),
    ;

    /**
     * code
     */
    private String code;

    /**
     * 厂商端名称
     */
    private String name;

    /**
     * 经销商端名称
     */
    private String distributorName;


    OnlinePaymentFlowStatusEnum(String code, String name, String distributorName){
        this.code = code;
        this.name = name;
        this.distributorName = distributorName;
    }

    /**
     * 根据code获取枚举
     * @param code
     * @return com.xbongbong.pro.enums.fund.enums.OnlinePaymentFlowStatusEnum
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static OnlinePaymentFlowStatusEnum getByCode(String code) {
        for (OnlinePaymentFlowStatusEnum cache : values()) {
            if (Objects.equals(code, cache.getCode())) {
                return cache;
            }
        }
        return null;
    }

    /**
     * 中文名称获取枚举
     *
     * @param name 名称
     * @return com.xbongbong.pro.enums.fund.enums.OnlinePaymentFlowStatusEnum
     * @throws
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static OnlinePaymentFlowStatusEnum getByName(String name) {
        for (OnlinePaymentFlowStatusEnum cache : values()) {
            if (Objects.equals(name, cache.getName())) {
                return cache;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getI18nName() {
        return name;
    }

    /**
     * 根据code获取枚举
     * @param code
     * @return com.xbongbong.pro.enums.fund.enums.OnlinePaymentFlowStatusEnum
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static OnlinePaymentFlowStatusEnum getByCode(Integer code){
        for (OnlinePaymentFlowStatusEnum cache : values()) {
            if (Objects.equals(cache.code, code)) {
                return cache;
            }
        }
        return null;
    }
}
